[monte_carlo.md] Update np.random → Generator API#741
[monte_carlo.md] Update np.random → Generator API#741Chihiro2000GitHub wants to merge 3 commits into
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
✅ Deploy Preview for taupe-gaufre-c4e660 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
HumphreyYang
left a comment
There was a problem hiding this comment.
Many thanks @Chihiro2000GitHub! It looks nice. Just one comment:
In this PR, a number of functions rely on the global rng object.
In some other PRs, rng is passed in as an argument instead. I think that approach is preferable here because it makes the source of randomness explicit and avoids hidden global state, which should make the functions easier to test and reason about.
So it would be nice to make a few minor edits so that these functions accept rng as an argument.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Thank you for the feedback, @HumphreyYang! I've updated all functions in |
Summary
This PR migrates legacy NumPy random API usage in
monte_carlo.mdas part of QuantEcon/meta#299.from numpy.random import randnwithrng = np.random.default_rng()in the imports block.randn(),randn(n),np.random.randn(M), andnp.random.randn(2, M)calls with the corresponding Generator API methods (rng.standard_normal()).Details
rngis defined once at module level in the imports block and reused throughout the lecture, including in the exercise solution blocks. In previous lectures, exercise solution blocks were typically treated as self-contained andrngwas redefined within each solution block. In this lecture, however, the exercise solutions were already not self-contained — they relied on the module-levelrandnimport rather than defining their own random source — so definingrngat module level and reusing it throughout is the more natural and consistent pattern here.No fixed seed was introduced. No Numba-related code was present.
Hi @mmcky and @HumphreyYang, I'd be grateful if you could take a look when you have time.